
// 思路：将传入的对象作为原型

function defCreate(obj){
    function F(){}
    F.prototype = obj
    return new F()
}


//测试
const Obj = {
    name:'vue',
    say:function(value){
        console.log(value)
    },
    setName(name){
        this.name = name
    },
    getName(){
        return this.name
    },
    obj:{
        arr:[1,2]
    }
}

const obj = defCreate(Obj)
obj.say('world')
obj.setName('js')
console.log(obj.getName());


//Object.create 和defCreate 都是个浅拷贝
const o = defCreate(Obj)
o.obj.arr[1] =0
o.setName('html')
console.log(Obj.obj.arr)